//- 先去这个pug文件中找
extends shopHead_nav.pug

block append pageStyle
	link(href="${relativePath}/static/css/shopping/shopIndex.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/materFinished.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/service.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/search.css" rel="stylesheet" type="text/css")

block matrialContent
	//- 成品材料内容
	div.matrialCon.layout
		div.searchallBox
			p.allkinds 所有分类 > 
			div.productsBox
				div.list
					ul
		div.meterialTabBox
			div.tabBtn
				div.left.fl
					span.zh.current 综合
						i
					span.xl 销量
						i
					//- span.jl 距离
					//- 	i
					//- span.xy 信誉
						i
					span.price 价格
						i
						em
			div.meterList
				ul
		
	//- 成品材料列表模板
	script#finished(type="text/html")
		li(num="{{id}}")
			a(href="javascript:;")
				img(src="{{base_img}}")
			div.btnProduct
				p
					<i class="fl red">{{sell_price}}</i>
					<span class="fr people">{{sale}}人付款</span>
				p
					<i class="fl listT">{{name}}</i>
					| {{if is_collect == 0}}
					| <span class="fr sc">收藏</span>
					| {{else}}
					| <span class="fr sc current">收藏</span>
					| {{/if}}
	//- 分页
	div.pageBox
		nav.pageNav
			div.paginationOne.page

block pageScript

	script.
		var MENUNUM
		$(function(){
			$("#cpcl").addClass("active");
			$("#cpcl").click(function(){
				window.location.href='materFinished.html';
			});
			$("#hyfw1").click(function(){
				window.location.href='industryServiceIndex.html';
			});
			$("#index").click(function(){
				window.location.href='materIndex.html';
			});
			
			$(".left span").click(function(){
				$(this).addClass("current").siblings().removeClass("current");
			})

			/*商品列表点击跳转*/
			$(".meterList").on("click","li img",function(){
				window.location.href="../../view/shopping/madeProcess.html?id="+$(this).closest("li").attr("num");
			})

			//- 搜索列表
			$.post(shopIp+"/search/searchGoodsCategory",{
				userToken:token,
				name:decodeURI(thisRequest.value),
			},function(res) {
				var cate = res.data;
				if(cate.length == 0) {
					$(".matrialCon").html("<img class='imgBig' src='${relativePath}/static/imgs/zw.png'/>")
					$(".matrialCon").css({
						"text-align":"center",
						"margin-bottom":"200px"
					})
					$(".page").hide()
				}else{
					for(var i=0;i<cate.length;i++) {
						var ele = '<li cateid='+cate[i].category_id+'><a href="javascript:;">'+cate[i].name+'</a></li>'
						$(".productsBox ul").append(ele)
					}	
				}
			})
			function searchList(pageNum,sync,asc,MENUNUM) {
				$(".meterList ul").html("");
				$.post(shopIp+"/search/searchGoods",{
					userToken:token,
					name:decodeURI(thisRequest.value),
					sell_price:sync,
					sale:asc,
					category_id:MENUNUM,
					page:pageNum,
					size:10
				},function(res) {
					var list = res.data;
					var catedata = list.data
					if(list.length == 0) {
						$(".matrialCon").html("<img class='imgBig' src='${relativePath}/static/imgs/zw.png'/>")
						$(".matrialCon").css({
							"text-align":"center",
							"margin-bottom":"200px"
						})
						$(".page").hide()
					}else{
						var listdata = list.data;
						if(listdata.length == 0) {
							$(".meterList ul").html("<img class='imgBig' src='${relativePath}/static/imgs/zw.png'/>")
							$(".meterList ul").css({
								"text-align":"center",
								"margin-bottom":"200px"
							})
							$(".page").hide()
							$(".tabBtn").hide()
						}else{
							for(var i=0;i<listdata.length;i++){
								var finished = template("finished",listdata[i]);
								$(".meterList ul").append(finished);
								$(".page").show()
								$(".tabBtn").show()
								$(".meterList ul").css({
									"text-align":"auto",
									"margin-bottom":"0"
								})
								$(".page").html("").pagination({
									pageCount : list.pageCount,
									current : pageNum,
									keepShowPN : true,
									count : 2,
									homePage : "1",
									endPage : list.pageCount,
									coping : true,
									prevContent : "< 上一页",
									nextContent : "下一页 >",
									callback : function(page) {
										searchList(page.getCurrent(),sync,asc,MENUNUM);
									}
								});
							}
						}
					}
				})
			}
			searchList(1)
			$(".zh").click(function() {
				searchList(1,"","",MENUNUM)
			})
			$(".xl").click(function() {
				searchList(1,"","asc",MENUNUM)
			})
			$(".price").toggle(function() {
				searchList(1,"asc","",MENUNUM)
			},function() {
				searchList(1,"desc","",MENUNUM)
			})
			//- 点击商品收藏
			$(".meterList").on("click",".sc",function(){
				if($(this).hasClass("current")) {
					$(this).removeClass('current');
					$.get(shopIp+"/Collection/collectionGoods?userToken="+token+"&goods_id="+$(this).closest("li").attr("num"),function(data) {
						layer.msg("取消成功");
					})
				}else{
					$(this).addClass('current');
					$.get(shopIp+"/Collection/collectionGoods?userToken="+token+"&goods_id="+$(this).closest("li").attr("num"),function(data) {
						layer.msg("收藏成功");
					})
				}
			});
			//- 点击头部列表
			$(".productsBox").on("click","li",function(){
				MENUNUM = $(this).attr("cateid")
				searchList(1,"","",MENUNUM)
				$(this).addClass("active").siblings().removeClass("active")
			})
		});